using System.Collections.Generic;
using SalesAndStoreApp.DAL.DAO;
using SalesAndStoreApp.DAL.Gateway;

namespace SalesAndStoreApp.BLL
{
    public class ProductManager   
    {
        private ProductGateway  productGateway = new ProductGateway();
        private ProductInventoryGateway productInventoryGateway = new ProductInventoryGateway();

        public List<Product> GetAll()
        {
            return productGateway.GetAll();
        }

        public Product GetById(int id)
        {
            return productGateway.GetById(id);
        }

        public List<Product> AddProductTo(Product product, List<Product> products)
        {
            bool hasProduct = false;
            foreach (var product1 in products)
            {
                if (product1.Id == product.Id)
                {

                    product1.Inventory.Quantity += product.Inventory.Quantity;
                    hasProduct = true;
                    break;
                }
            }


            if (!hasProduct)
                {
                    products.Add(product);
                }
          return products;
        }


        public string SaveProductSetup(Product product)
        {
            
            return productInventoryGateway.SaveProductSetup(product);
        }
    }
}